[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
dup2() Reassign a File Handle
#include <io.h> Required for declarations only
int dup2(handle1, handle2);
int handle1; Handle referring to open file
int handle2; Any handle value
dup2() causes 'handle2' to refer to the same file as 'handle1', which
is associated with a previously opened file. Either file handle can
be used to carry out operations on the file, because both handles use
the same file pointer.
Returns: 0, if successful. On error, -1 is returned and
'errno' is set to:
EBADF Invalid file handle
EMFILE Too many files open
Notes: In the example below, if file handle 3 is already
open, it will be closed first.
-------------------------------- Example ---------------------------------
These statements make file handle 3 refer to the same file as file
handle 1.
#include <io.h>
#include <stdlib.h>
int fh;
main()
{
fh = dup2(1,3);
if (fh == -1)
perror("error setting duplicate file handles");
}
See Also:
close()
creat()
open()
dup()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson